/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.jSkyRoom.bridge.major;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import ru.jSkyRoom.interfaces.major.Book;
import ru.jSkyRoom.interfaces.major.Keyword;
import ru.jSkyRoom.interfaces.major.Spell;
import ru.jSkyRoom.interfaces.stub.Art;
import ru.jSkyRoom.interfaces.stub.JSkyScriptPackage;
import ru.jSkyRoom.interfaces.stub.JSkySound;
import ru.jSkyRoom.interfaces.stub.StaticObject;
import ru.jSkyRoom.interfaces.sub.Icon;
import ru.jSkyRoom.interfaces.sub.JSkyModel;
import skyproc.BOOK;
import skyproc.BOOK.BookFlag;
import skyproc.FormID;
import skyproc.Model;
import skyproc.ScriptPackage;
import skyproc.genenums.ActorValue;

/**
 *
 * @author Rakev
 */
public class BookBridge extends DescriptionedMajorBridge<BOOK> implements Book {

    public BookBridge(BOOK adapting) {
        super(adapting);
    }

    @Override
    public JSkyScriptPackage getScriptPackage() {
        ScriptPackage scriptPackage = getRawObject().getScriptPackage();
        return getBridgeFactory().createBridge(scriptPackage);
    }

    @Override
    public JSkyModel getModel() {
        Model model = getRawObject().getModelData();
        return getBridgeFactory().createBridge(model);
    }

    @Override
    public Icon getInventoryIcon() {
        return new Icon() {
            @Override
            public String getFileName() {
                return getRawObject().getInventoryImage();
            }

            @Override
            public void setFileName(String filename) {
                getRawObject().setInventoryImage(filename);
            }
        };
    }

    @Override
    public Icon getMessageIcon() {
        return new Icon() {
            @Override
            public String getFileName() {
                return getRawObject().getMessageImage();
            }

            @Override
            public void setFileName(String filename) {
                getRawObject().setMessageImage(filename);
            }
        };
    }

    @Override
    public JSkySound getPickupSound() {
        FormID soundId = getRawObject().getPickupSound();
        return getFinderFactory().createJSkySoundFinder().find(soundId);
    }

    @Override
    public void setPickupSound(JSkySound sound) {
        FormID id = getIdProducer().produce(sound);
        getRawObject().setPickupSound(id);
    }

    @Override
    public JSkySound getDropSound() {
        FormID soundId = getRawObject().getDropSound();
        return getFinderFactory().createJSkySoundFinder().find(soundId);
    }

    @Override
    public void setDropSound(JSkySound sound) {
        FormID id = getIdProducer().produce(sound);
        getRawObject().setDropSound(id);
    }

    @Override
    public Set<Keyword> getKeywords() {
        Collection<FormID> keyWordFormIds = getRawObject().getKeywordSet().getKeywordRefs();
        Collection<Keyword> keyWords = getFinderFactory().createKeywordFinder().find(keyWordFormIds);

        return Collections.unmodifiableSet(new HashSet<>(keyWords));
    }

    @Override
    public void addKeyword(Keyword keyword) {
        getRawObject().getKeywordSet().addKeywordRef(keyword.getForm());
    }

    @Override
    public void removeKeyword(Keyword keyword) {
        getRawObject().getKeywordSet().removeKeywordRef(keyword.getForm());
    }

    @Override
    public int getValue() {
        return getRawObject().getValue();
    }

    @Override
    public void setValue(int value) {
        getRawObject().setValue(value);
    }

    @Override
    public float getWeight() {
        return getRawObject().getWeight();
    }

    @Override
    public void setWeight(float weight) {
        getRawObject().setWeight((float) weight);
    }

    @Override
    public boolean getFlag(BookFlag flag) {
        return getRawObject().get(flag);
    }

    @Override
    public void setFlag(BookFlag flag) {
        getRawObject().set(flag, true);
    }

    @Override
    public void unsetFlag(BookFlag flag) {
        getRawObject().set(flag, false);
    }

    @Override
    public ActorValue getTeachesActorValue() {
        return getRawObject().getTeachesAV();
    }

    @Override
    public void setTeachesActorValue(ActorValue actorValue) {
        getRawObject().setTeachesAV(actorValue);
    }

    @Override
    public Spell getTeachesSpell() {
        FormID id = getRawObject().getTeachesSpell();
        return getFinderFactory().createSpellFinder().find(id);
    }

    @Override
    public void setTeachesSpell(Spell spell) {
        FormID id = getIdProducer().produce(spell);
        getRawObject().setTeachesSpell(id);
    }

    @Override
    public StaticObject getInventoryArt() {
        FormID id = getRawObject().getInventoryArt();
        return getFinderFactory().createStaticObjectFinder().find(id);
    }

    @Override
    public void setInventoryArt(ru.jSkyRoom.interfaces.stub.StaticObject art) {
        FormID id = getIdProducer().produce(art);
        getRawObject().setInventoryArt(id);
    }

    @Override
    public String getText() {
        return getRawObject().getText();
    }

    @Override
    public void setText(String text) {
        getRawObject().setText(text);
    }
}
